package com.wd.live;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.drz.base.fragment.MvvmLazyFragment;
import com.drz.base.viewmodel.IMvvmBaseViewModel;
import com.drz.common.router.RouterFragmentPath;
import com.google.android.material.tabs.TabLayout;
import com.wd.live.adapter.LiveFragmentPageAdapter;

import com.wd.live.databinding.LiveFragmentMyliveBinding;
import com.wd.live.liveattention.LiveAttentionFragment;
import com.wd.live.livemap.LiveMapFragment;
import com.wd.live.liverecommend.LiveRecommendFragment;
import com.wd.live.livestreaming.LiveStreamingFragment;

import java.util.ArrayList;

@Route(path = RouterFragmentPath.Live.PAGER_LIVE)
public class LiveFragment extends MvvmLazyFragment<LiveFragmentMyliveBinding, IMvvmBaseViewModel> {

    private ArrayList<Fragment> fragments;
    private LiveFragmentPageAdapter adapter;

    @Override
    protected void onFragmentFirstVisible() {
        super.onFragmentFirstVisible();
        initData();
        fragments = new ArrayList<>();
        fragments.add(new LiveAttentionFragment());
        fragments.add(new LiveRecommendFragment());
        fragments.add(new LiveStreamingFragment());
        fragments.add(new LiveMapFragment());
        //适配器里的setdata方法
        adapter.setData(fragments);

        viewDataBinding.liveViewpager.setCurrentItem(1);


    }



    public void initData(){
        adapter = new LiveFragmentPageAdapter(getChildFragmentManager(), FragmentPagerAdapter.BEHAVIOR_SET_USER_VISIBLE_HINT);

        viewDataBinding.liveViewpager.setAdapter(adapter);

        viewDataBinding.liveTablayou.setupWithViewPager(viewDataBinding.liveViewpager);

        viewDataBinding.liveViewpager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(viewDataBinding.liveTablayou));

        viewDataBinding.liveTablayou.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewDataBinding.liveViewpager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }



    @Override
    public int getBindingVariable() {

        return 0;
    }
    @Override
    public int getLayoutId() {
        return R.layout.live_fragment_mylive;

    }

    @Override
    protected IMvvmBaseViewModel getViewModel() {
        return null;
    }

    @Override
    protected void onRetryBtnClick() {

    }
}
